package com.knight.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * 自定义Aspect
 *
 * @author knight
 */
@Aspect
@Component
public class TimeAspect {

    /**
     * 还有其他的注解也是类似的使用方式 @after @before
     *
     * @return
     */
    @Around(value = "execution(* com.knight.controller.UserController.*(..))")
    public Object handleControllerMethod(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("time aspect start");
        Object[] args = pjp.getArgs();
        for (Object arg : args) {
            System.out.println("arg is " + arg);
        }
        long start = System.currentTimeMillis();
        // 处理拦截的方法
        Object result = pjp.proceed();
        System.out.println("time aspect 耗时:" + (System.currentTimeMillis() - start));
        System.out.println("time aspect end");
        return result;
    }
}
